package com.ruoyi.monitor.model.Subject;

import com.ruoyi.monitor.domain.Pollutant;
import com.ruoyi.monitor.model.Abstract.Observer;
import com.ruoyi.monitor.model.Abstract.Subject;
import com.ruoyi.monitor.service.ISysMessageService;
import com.ruoyi.monitor.utils.Email.MailCenter;
import com.ruoyi.monitor.utils.Msg.SMSCenter;
import com.ruoyi.system.service.ISysUserService;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
public class QualitySubject implements Subject<Observer> {

    private List<Pollutant> pollutants = new ArrayList<>();

    private Pollutant pollutant;

    public Pollutant getPollutant() {
        return pollutant;
    }

    public void setPollutant(Pollutant pollutant) {
        this.pollutant = pollutant;
        this.pollutants.add(this.pollutant);
        notifyAllObservers();
    }

    public List<Pollutant> getPollutants() {
        return pollutants;
    }

    public void setPollutants(List<Pollutant> pollutants) {
        this.pollutants = pollutants;
    }

    @Override
    public void registerObserver(Observer obs) {
        if (list.size() == 1){
            list.remove(0);
        }
        list.add(obs);
    }

    @Override
    public void removeObserver(Observer obs) {
        list.remove(obs);
    }

    @Override
    public void notifyAllObservers() {
        System.out.println("观察者更新中......");
        for (Observer obs : list) {
            // 更新每一个观察者中的信息
            obs.update(this);
        }
    }


}
